package day05;

import java.util.Stack;

public class Code05_GetMinStack {

    public static class MyStack {
        private Stack<Integer> stackData;
        private Stack<Integer> stackMin;

        public MyStack() {
            this.stackData = new Stack<Integer>();
            this.stackMin = new Stack<Integer>();
        }

        public void push(int newNum) {
            stackData.push(newNum);
            if (stackMin.isEmpty()) {
                stackMin.push(newNum);
            } else {
                stackMin.push(Math.min(newNum, stackData.peek()));
            }
        }

        public int pop() {
            int value = stackData.pop();
            stackMin.pop();
            return value;
        }

        public int getmin() {
            return stackMin.peek();
        }
    }

}
